<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="a" />
    <input type="text" />
    <span id="b"></span>
    <script>
      var val = "coderqian";
      var obj = {};
      Object.defineProperty(obj, "hello", {
        set: function (newval) {
          val = newval;
          document.getElementById("a").value = newval;
          document.getElementById("b").innerHTML = newval;
        },
        get: function () {
          console.log("getval", val);
          return val;
        },
      });
      addEventListener("keyup", function (e) {
        obj.hello = e.target.value;
      });
    </script>
  </body>
</html>
